package com.mec.offload.controller;


import com.mec.offload.model.SubTask;
import com.mec.offload.service.SubTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/offload/SubTask")
@CrossOrigin
public class SubTaskController{
    @Autowired
    SubTaskService subTaskService;
    //@CrossOrigin(origins = "*")
    @RequestMapping("/getSubTaskLoc")
    @ResponseBody
    public List<SubTask> getSubTaskLoc(Integer TaskId)
    {
        try{
            return subTaskService.getTaskByTaskLoc(TaskId);
        }catch (Exception e)
        {
            e.printStackTrace();
            return null;
        }
    }
    //@CrossOrigin(origins = "*")
    @RequestMapping("/getSubTaskOffload")
    @ResponseBody
    public List<SubTask> getSubTaskOffload(Integer TaskId)
    {
        try{
            return subTaskService.getTaskByTaskOffload(TaskId);
        }catch (Exception e)
        {
            e.printStackTrace();
            return null;
        }
    }

    //切割2：得到父的所有子做前端列表展示
    //@CrossOrigin(origins = "*")
    @RequestMapping("/getSubTask")
    @ResponseBody
    public List<SubTask> getSubTask(Integer TaskId)
    {
        try{
            return subTaskService.getSubMission(TaskId);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
    //@CrossOrigin(origins = "*")
    @RequestMapping("/getSubTaskInMsOnce")
    @ResponseBody
    public List<SubTask> getSubTaskInMsOnce(Integer TaskId)
    {
        try {

            return subTaskService.getSubTaskInMsOnce(TaskId);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /*
        docin：切割
        1. 是否可切判断——至少有2个子任务+第一步决策有sig=1
        2. 调用决策算法
        3. 返回决策后切割结果【所有子任务和sig】
    */

//    //终端任务表 layui
    //@CrossOrigin(origins = "*")
    @RequestMapping("/getSubTask11")
    @ResponseBody
    public List<SubTask> getSubTaskdou(Integer TaskId)
    {
        try{

            return subTaskService.getSubMission(TaskId);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }


}